<template>
	<view class="pages">
		<view class="head flex_op" >
			<view class="head_left ali-c" @click="fhui">
				<image src="http://oos-cn.ctyunapi.cn/hfclass/fanhui.png?Signature=UxKzt/fO7QiCKXVEBjkGnSGdoIw%3D&AWSAccessKeyId=65b300139cc5a0aa9572&Expires=865585101242" style="width: 16rpx;height: 26rpx;margin-right: 20rpx;"  ></image>
				<text>返回</text>
			</view>
			<view style="position: relative;left: -16rpx;">脊柱侧弯报告</view>
			<view class="head_right" ></view>
		</view>
		<view style="height: 130rpx;"></view>
		<view class="cu-form-group" style="background-color: #1CBBB4;color: #FFFFFF;">
			<view class="title">日期选择</view>
			<picker mode="date" fields="year" :value="date" start="2015" :end="times" @change="DateChange">
				<view class="picker">
					{{date}}
				</view>
			</picker>
		</view>
		<!-- <view class="cu-form-group">
			<view class="title">选择上报人</view>
			<picker @change="hange" :value="index" :range="arrId">
				<view class="picker">
					{{index>-1?arrId[index]:'选择'}}
				</view>
			</picker>
		</view> -->
		<view class="allbox" v-if="list.length>0">
			<view class="jizhu flex_op" @click="cizhu(item)" v-for="(item, index) in list" :key='index'>
				<text>{{item.name}}  脊柱侧弯报告</text>
				<image src="http://oos-cn.ctyunapi.cn/hfclass/%E9%80%89%E6%8B%A9%E7%AE%AD%E5%A4%B415X22.png?Signature=8Ry%2BydghTC67iii673JW%2BmJlX5s%3D&AWSAccessKeyId=65b300139cc5a0aa9572&Expires=865585102035"></image>
			</view>
		</view>
		<view class="flexc srcCss" v-else>
			<image src="/static/tabbar/kong.png" mode="widthFix" ></image>
		</view>
		
		<!-- //弹窗 -->
		<view v-if="IsRelieve" class="MaskLayer" @click="IsRelieve=false"></view>
		<view class="CPM" v-if="IsRelieve">
			<view class="CPM_box">
				<view>添加上报人信息</view>
				<view @click="confirm">确定</view>
			</view>
		</view>
	</view>
</template>

<script>
	import App from '@/App.vue'
	export default {
		data() {
			return {
			    IsRelieve: false,
				date:'',
				list:[],
				pick:[],
				times:null,
				arrId:[],
				index:0
			}
		},
		onShow() {
			this.getTime() //获取时间
			var that = this
			const ArrId=uni.getStorageSync('ArrId')
			this.arrId=ArrId
			// console.log(ArrId)
			if(ArrId.length==0||ArrId==''||ArrId==[]){
				uni.showLoading({
					title:"加载中..."
				})
				uni.request({
					method: 'POST',
					// url: App.globalData.baseUrl + '/api/services/app/organUser/GetBingList',
					url: App.globalData.baseUrl + '/api/services/app/organUser/GetBingList',
					success(res) {
						that.pick = []
						that.getUserId()
						if (res.data.success == true) {
							const ultarr = res.data.result
							
							ultarr.sort(function(a, b) {
								return b.name.length - a.name.length
							})
							if (ultarr.length == 1 && ultarr[0].address == null && ultarr[0].familyCount == 0 && ultarr[0].identityNumber ==
								null &&
								ultarr[0].name == '' && ultarr[0].phoneNumber == null) {
								that.userId = ultarr[0].userId
								uni.hideLoading()
								that.IsRelieve = true
							} else {
								
								that.arrId = ultarr
								uni.setStorageSync('ArrId', that.arrId)
								ultarr.forEach((item, index) => {
									that.pick.push(item.name)
								})
				
								if (ultarr.length > 0 & that.index == -1) {
									that.index = 0
								}
								uni.hideLoading()
								that.IsRelieve = false
							}
						} else {
							uni.hideLoading()
							that.IsRelieve = false
							uni.showToast({
								title: res.data.error.message,
								duration: 2000,
								icon: 'none'
							})
							if (res.data.error.code == 401) {
								
								uni.showToast({
									icon: 'none',
									duration: 2000,
									title: '马上开始重新登录'
								})
				
								let cl = setTimeout(() => {
									window.location.href = '/wx/GetCode'
									clearTimeout(cl)
								}, 2000)
				
							}
						}
					},
					fail(res) {
						uni.showToast({
							icon: 'none',
							duration: 2000,
							title: '未登录'
						})
						let cl = setTimeout(() => {
							window.location.href = '/wx/GetCode'
							clearTimeout(cl)
						}, 2000)
					}
				})
			}else{
				this.getUserId()
			}	
		},
		methods:{
			getTime() {
				let date = new Date(),
					that = this
				var year = date.getFullYear();
				var month = date.getMonth() + 1;
				var strDate = date.getDate();
				var hours=date.getHours()
				var minutes=date.getMinutes()
				if (month >= 1 && month <= 9) {
					month = "0" + month;
				}
				if (strDate >= 0 && strDate <= 9) {
					strDate = "0" + strDate;
				}
				that.times = year + '-' + month + '-' + strDate;
				that.date=year
			},
			cizhu(item){
				let items=JSON.stringify(item)
				console.log(items)
				uni.navigateTo({
					url:'/pages/jiZhuCeWan/details?date='+items
				})
			},
			DateChange(e) {
				this.date = e.detail.value
				this.getUserId()
			},
			getUserId(){
				var _this=this;
				uni.request({
					method: 'POST',
					url: App.globalData.baseUrl + '/api/services/app/scoliosis/GetScoliosisByUserId',
					data:{
						"userId":0,
						"year": Number(_this.date)
					},
					success(res) {
						// console.log(res)
						if(res.data.success){
							_this.list=res.data.result
							// console.log(_this.list)
						}
					}
				})
			},
			mag(msg){
				uni.showToast({
					title:msg,
					icon:'none',
					duration:3000
				})
			},
			fhui(){
				uni.navigateBack({
					delta:1
				})
			},
		}
	}
</script>

<style>
	.pages{
		width: 100%;	
	}
	.head{
		height: 100rpx;
		width: 100%;
		background-color: #FFFFFF;
		padding: 0 30rpx;
		box-sizing: border-box;
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-size: 30rpx;
		position: fixed;
		z-index: 10;
		box-shadow: 1rpx 1rpx 10rpx 2rpx #DDDDDD;
	}
	.allbox{
		padding:30rpx;
	}
	.jizhu{
		width: 100%;
		padding: 30rpx 24rpx;
		border-radius: 8rpx;
		border: 1rpx solid #bfbfbf;
	}
	.jizhu>image{width: 14rpx; height: 26rpx;}
	.srcCss{
		width: 100%;
		height: 100vh;
	}
	.srcCss>image{
		width: 400rpx;
		height: 400rpx;
		margin-bottom: 300rpx;
	}
</style>
